Setting up Eclipse with TomcatIntroductionWhen I started using WebWork I went through the trouble of setting up my development environment to cater for web development. What I wanted was a fast turn around time, i.e. if I changed a .jsp file I could just refresh the web browser to see the changes. Also changes in WebWork related configurations will have immediate effect. And finally minor java changes from within Eclipse is also hot replaced. I will document how to setup Eclipse and install a tomcat plugin so all is integrated within Eclipse and you can easily start, stop, restart Tomcat, see output in the Eclipse console, debug, make code changes on the fly, etc. etc. so development is a joy. If you are fortunate enough to use the JetBrains IDEA editor then all this is already setup for you. PrefaceI used these tools Windows XP Install Tomcat PluginThere are several Tomcat plugins to Eclipse, and I tried several versions. I found that Sysdeo was the best one for my needs. There is a good Eclipse plugin homepage at http://www.eclipse-plugins.info Download the Sysdeo plugin from it's homepage at http://www.sysdeo.com/eclipse/tomcatplugin Unzip the downloaded file to <ECLIPSE_HOME>\plugins Installing TomcatIf you don't have Tomcat installed then download it from http://tomcat.apache.org Configure Tomcat Plugin in EclipseRestart/Start Eclips so the plugin is loaded. If the plugin is working you will immediately notice 3 new icons in the Eclipse toolbar Create a new ProjectWhen you create a new project in Eclipse you folders follow a certain structure standard to make this work. I have this folder structure <project_home> In the lib folder copy your needed .jar files. I have these files: commons-logging.jar
And in WEB-INF your should have web.xml and the Spring configuration file. And if you use Spring log4j ConfigListener you could also store log4j.properties here. I have these 3 files: The spring configuration file is basically empty to start with ApplicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans default-autowire="autodetect"> </beans>
And the web.xml <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>/WEB-INF/log4j.properties</param-value> </context-param> <filter> <filter-name>webwork</filter-name> <filter-class>com.opensymphony.webwork.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>webwork</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <servlet> <servlet-name>freemarker</servlet-name> <servlet-class>com.opensymphony.webwork.views.freemarker.FreemarkerServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>freemarker</servlet-name> <url-pattern>*.ftl</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app>
And my log4j.properties log4j.rootLogger=INFO, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss} %-5p %c - %m%n
#log4j.category.org.springframework=DEBUG
#log4j.category.com.opensymphony.webwork=DEBUG
#log4j.category.com.opensymphony.xwork=DEBUG
Now the tricky part is that we still need some configuration files for WebWork that usually resides in the classpath folder. These files we must store outside the webapp folder due Eclipse hot java code deployer. So these files: This is my webwork.properties that is setup for development webwork.objectFactory = spring webwork.devMode = true webwork.configuration.xml.reload = true webwork.url.http.port = 8080
And then the xwork.xml where we configure our action <!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.1.1//EN" "http://www.opensymphony.com/xwork/xwork-1.1.1.dtd"> <xwork> <include file="webwork-default.xml"/> <package name="default" extends="webwork-default"> </package> </xwork>
Now we are nearly ready. We must tell Eclipse to output the compiled source files to webapp/WEB-INF/classes. This is done by Project -> Properties. Then select the Java Build Path tab. Then type "<project_name>webapp/WEB-INF/classes" in the default output folder. Then Eclipse would put the compiled source files to our web app classes folder AND also copy all other configuration files within the src/java folder, and thus also our webwork.properties and xwork.xml is copied. It is important to put webwork.properties and xwork.xml in the src/java folder as Eclipse will automatically clean the build source folder when it compiles. So if we put webwork.properties and xwork.xml in the WEB-INF/classes folder Eclipse will delete them. That is why we put the files in src/java instead. Now we are done configuring and setup our development environment in Eclipse. Now let's test it. Now let's make the famous Hello World and se code changes on the fly
|